﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sirene.Core;

namespace Sirene.Main
{
    public partial class frMain : Form
    {
        public frMain()
        {
            InitializeComponent();
            mainMenu.Enabled = true;
        }

        private SireneAction sa = new SireneAction();


        private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
        {            
            this.openFileDialog.FileName = sa.strFileName;
            
            if (DialogResult.OK == this.openFileDialog.ShowDialog(this))
            {
                if (true)
                {
                    sa.strFileName = this.openFileDialog.FileName;
                }
                else
                {
                    sa.strFileName = String.Empty;
                }
            }
        }

        private void btPlay_Click(object sender, EventArgs e)
        {    
            sa.Play();

            // put it to some obvious method
            btPlay.Visible = false;
            btPause.Visible = true;

            sa.sv.Width = pictureBoxSpectrum.Width;
            sa.sv.Height = pictureBoxSpectrum.Height;
            spectrumTimer.Start();

            foreach (var item in sa.sd.GetTags)
            {
                //listBox1.Items.Add(item.Key+" "+item.Value);
                //playListItems.Items.Add();
            }

            pictureCurrentPlay.Image = sa.sd.GetImageCover;
            labelElapsed.Text = sa.sd.GetElapsedTime;
            
        }

        private void frMain_Load(object sender, EventArgs e)
        {
            // some my hack to provide this to safe 
            IntPtr IP = new IntPtr(this.Handle.ToInt32());
            sa.Load(IP);

            playListItems.Columns.Add("#", 30, HorizontalAlignment.Left);
            playListItems.Columns.Add("Title", 140, HorizontalAlignment.Left);
            playListItems.Columns.Add("Artist", 130, HorizontalAlignment.Left);
            playListItems.Columns.Add("Album", 110, HorizontalAlignment.Left);
            playListItems.Columns.Add("Genre", 100, HorizontalAlignment.Left);
            playListItems.Columns.Add("Year", 100, HorizontalAlignment.Left);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sa.Exit();
        }

        private void spectrumTimer_Tick(object sender, EventArgs e)
        {
            pictureBoxSpectrum.Image = sa.sv.GetSpectrum;
            labelElapsed.Text = sa.sd.GetElapsedTime;
            labelRemain.Text = sa.sd.GetRemainingTime;
        }

        private void btPause_Click(object sender, EventArgs e)
        {
            sa.Pause();
        }

        private void btPreviews_Click(object sender, EventArgs e)
        {
            sa.Previews();
        }

        private void btNext_Click(object sender, EventArgs e)
        {
            sa.Next();
        }


        
    }
}
